package com.example.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    /**
     * 可以注入多个doket，也就是多个版本的api，可以在看到有三个版本groupName不能是重复的，v1和v2是ant风格匹配，配置文件
     * @return
     */

    @Bean
    public Docket menuApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("menu")
                .apiInfo(menuApiInfo())
                .select()
                //RequestHandlerSelectors，配置要扫描接口的方式
                //basePackage指定要扫描的包
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                .paths(PathSelectors.ant("/menu/**"))
                .build()
                //配置是否启动swagger
                .enable(true);
    }

    private ApiInfo menuApiInfo() {

        //作者信息
        Contact contact = new Contact("Chenlh","","1430505321@qq.com");
        return new ApiInfo(
                "Menu的API文档",
                "这是菜单的接口文档",
                "v1.0",
                "",
                contact,
                "",
                "",
                new ArrayList<>()
        );
    }

    @Bean
    public Docket userApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("user")
                .apiInfo(userApiInfo())
                .select()
                //RequestHandlerSelectors，配置要扫描接口的方式
                //basePackage指定要扫描的包
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                .paths(PathSelectors.ant("/user/**"))
                .build()
                //配置是否启动swagger
                .enable(true);
    }

    private ApiInfo userApiInfo() {

        //作者信息
        Contact contact = new Contact("Chenlh","","1430505321@qq.com");
        return new ApiInfo(
                "User的API文档",
                "这是用户的接口文档",
                "v1.0",
                "",
                contact,
                "",
                "",
                new ArrayList<>()
        );
    }

    @Bean
    public Docket orderApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("chenqiuran")
                .apiInfo(orderApiInfo())
                .select()
                //RequestHandlerSelectors，配置要扫描接口的方式
                //basePackage指定要扫描的包
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                .paths(PathSelectors.ant("/order/**"))
//                .paths(PathSelectors.ant("/menu/**"))
                .build()
                //配置是否启动swagger
                .enable(true);
    }

    private ApiInfo orderApiInfo() {

        //作者信息
        Contact contact = new Contact("chenqiuran","","1097330798@qq.com");
        return new ApiInfo(
                "订单服务",
                "订单服务的接口文档",
                "v1.0",
                "",
                contact,
                "",
                "",
                new ArrayList<>()
        );
    }
    @Bean
    public Docket commentApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("hyf")
                .apiInfo(commentApiInfo())
                .select()
                //RequestHandlerSelectors，配置要扫描接口的方式
                //basePackage指定要扫描的包
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                .paths(PathSelectors.ant("/comment/**"))
                .build()
                //配置是否启动swagger
                .enable(true);
    }

    private ApiInfo commentApiInfo() {

        //作者信息
        Contact contact = new Contact("hyf","","1436960071@qq.com");
        return new ApiInfo(
                "回复服务",
                "回复服务的接口文档",
                "v1.0",
                "",
                contact,
                "",
                "",
                new ArrayList<>()
        );
    }


    @Bean
    public Docket accountApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("yucs")
                .apiInfo(commentApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                .paths(PathSelectors.ant("/account/**"))
                .build()
                //配置是否启动swagger
                .enable(true);
    }
    private ApiInfo accountApiInfo() {

        //作者信息
        Contact contact = new Contact("yucs","","yucsa@enn.cn");
        return new ApiInfo(
                "账号接口_主要为注册登录等",
                "账号相关的接口文档",
                "v1.0",
                "",
                contact,
                "",
                "",
                new ArrayList<>()
        );
    }

    @Bean
    public Docket cartApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("cart")
                .apiInfo(cartApiInfo())
                .select()
                //RequestHandlerSelectors，配置要扫描接口的方式
                //basePackage指定要扫描的包
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                .paths(PathSelectors.ant("/cart/**"))
                .build()
                //配置是否启动swagger
                .enable(true);
    }

    private ApiInfo cartApiInfo() {

        //作者信息
        Contact contact = new Contact("Chenlh","","1430505321@qq.com");
        return new ApiInfo(
                "Cart的API文档",
                "这是购物车的接口文档",
                "v1.0",
                "",
                contact,
                "",
                "",
                new ArrayList<>()
        );
    }

    @Bean
    public Docket kafkaApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("kafka")
                .apiInfo(kafkaApiInfo())
                .select()
                //RequestHandlerSelectors，配置要扫描接口的方式
                //basePackage指定要扫描的包
                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                .paths(PathSelectors.ant("/kafka/**"))
                .build()
                //配置是否启动swagger
                .enable(true);
    }

    private ApiInfo kafkaApiInfo() {

        //作者信息
        Contact contact = new Contact("kafka","","1097330798@qq.com");
        return new ApiInfo(
                "订单服务",
                "订单服务的接口文档",
                "v1.0",
                "",
                contact,
                "",
                "",
                new ArrayList<>()
        );
    }
}
